home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / languages / pcq_incl3v1.lha / Utility / Hooks.i < prev    next >
Encoding:
Text File  |  1994-04-15  |  2.5 KB  |  81 lines

  1. { Hooks.i }
  2.  
  3. {$I   "Include:Exec/Types.i"}
  4. {$I   "Include:Exec/Nodes.i"}
  5.  
  6. { new standard hook structure }
  7.  
  8. Type
  9.     Hook = Record
  10.      h_MinNode  : MinNode;
  11.      h_Entry    : ^Integer;   { assembler entry point        }
  12.      h_SubEntry : ^Integer;   { often HLL entry point        }
  13.      h_Data     : Address;    { owner specific               }
  14.     END;
  15.     HookPtr = ^Hook;
  16.  
  17. {
  18.  * Hook calling conventions:
  19.  *      A0 - pointer to hook data structure itself
  20.  *      A1 - pointer to parameter structure ("message") typically
  21.  *           beginning with a longword command code, which makes
  22.  *           sense in the context in which the hook is being used.
  23.  *      A2 - Hook specific address data ("object," e.g, GadgetInfo)
  24.  *
  25.  * Control will be passed to the routine h_Entry.  For many
  26.  * High-Level Languages (HLL), this will be an assembly language
  27.  * stub which pushes registers on the stack, does other setup,
  28.  * and then calls the function at h_SubEntry.
  29.  *
  30.  * The C standard receiving code is:
  31.  * CDispatcher( hook, object, message )
  32.  *     struct Hook      *hook;
  33.  *     APTR             object;
  34.  *     APTR             message;
  35.  *
  36.  * NOTE that register natural order differs from this convention
  37.  * for C parameter order, which is A0,A2,A1.
  38.  *
  39.  * The assembly language stub for "vanilla" C parameter conventions
  40.  * could be:
  41.  
  42.  _hookEntry:
  43.         move.l  a1,-(sp)                ; push message packet pointer
  44.         move.l  a2,-(sp)                ; push object pointer
  45.         move.l  a0,-(sp)                ; push hook pointer
  46.         move.l  h_SubEntry(a0),a0       ; fetch C entry point ...
  47.         jsr     (a0)                    ; ... and call it
  48.         lea     12(sp),sp               ; fix stack
  49.         rts
  50.  
  51.  * with this function as your interface stub, you can write
  52.  * a Hook setup function as:
  53.  
  54.  SetupHook( hook, c_function, userdata )
  55.  struct Hook    *hook;
  56.  ULONG          (*c_function)();
  57.  VOID           *userdata;
  58.  
  59.         ULONG   (*hookEntry)();
  60.  
  61.         hook->h_Entry =         hookEntry;
  62.         hook->h_SubEntry =      c_function;
  63.         hook->h_Data =                  userdata;
  64.  
  65.  
  66.  * with Lattice C pragmas, you can put the C function in the
  67.  * h_Entry field directly if you declare the function:
  68.  
  69. ULONG __saveds __asm
  70. CDispatcher(    register __a0 struct Hook       *hook,
  71.                 register __a2 VOID              *object,
  72.                 register __a1 ULONG             *message );
  73.  *
  74.  ***}
  75.  
  76.  
  77. FUNCTION CallHookPkt(h : HookPtr; object, paramPkt : Address) : Integer;
  78.     External;
  79.  
  80.  
  81.